-- monster_type_defense
-- created by shuzy
-- 受到某类敌人攻击时，降低百分比所受伤害

return {
    -- 返回的是提升的攻击点数
    apply = function(prop, baseValue)
        if (prop[3] == 0) then
            return 0;
        end

        -- 降低的千分比
        local v = math.modf(baseValue * prop[3] / 1000);

        -- 最少减少1点伤害
        v = math.max(1, v);

        -- 返回减少的值，不能高于伤害
        return math.min(v,baseValue);
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        local style = prop[2];
        local num = prop[3] / 10;

        if type(style) == "string" then
            if style == "living" then
                desc = string.gsub(desc, "{0}", getLocStr("living"));
            elseif style == "boss" then
                desc = string.gsub(desc, "{0}", getLocStr("boss"));
            end
        else
            if style == 1 then
                desc = string.gsub(desc, "{0}", getLocStr("undead"));
            elseif style == 2 then
                desc = string.gsub(desc, "{0}", getLocStr("beast"));
            elseif style == 4 then
                desc = string.gsub(desc, "{0}", getLocStr("element"));
            elseif style == 8 then
                desc = string.gsub(desc, "{0}", getLocStr("plant"));
            elseif style == 16 then
                desc = string.gsub(desc, "{0}", getLocStr("human"));
            elseif style == 32 then
                desc = string.gsub(desc, "{0}", getLocStr("demon"));
            elseif style == 64 then
                desc = string.gsub(desc, "{0}", getLocStr("machine"));
            end
        end

        desc = string.gsub(desc, "{1}", num);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};